home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kicondialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-01  |  9.2 KB  |  351 lines

  1. /* vi: ts=8 sts=4 sw=4
  2.  *
  3.  * This file is part of the KDE project, module kfile.
  4.  * Copyright (C) 2000 Geert Jansen <jansen@kde.org>
  5.  *           (C) 2000 Kurt Granroth <granroth@kde.org>
  6.  *           (C) 1997 Christoph Neerfeld <chris@kde.org>
  7.  *           (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
  8.  *
  9.  * This is free software; it comes under the GNU Library General
  10.  * Public License, version 2. See the file "COPYING.LIB" for the
  11.  * exact licensing terms.
  12.  */
  13.  
  14. #ifndef __KIconDialog_h__
  15. #define __KIconDialog_h__
  16.  
  17. #include <qstring.h>
  18. #include <qstringlist.h>
  19. #include <qpushbutton.h>
  20.  
  21. #include <kicontheme.h>
  22. #include <kdialogbase.h>
  23. #include <kiconview.h>
  24.  
  25. class QComboBox;
  26. class QTimer;
  27. class QKeyEvent;
  28. class QRadioButton;
  29. class KProgress;
  30. class KIconLoader;
  31.  
  32. /**
  33.  * Icon canvas for KIconDialog.
  34.  */
  35. class KIO_EXPORT KIconCanvas: public KIconView
  36. {
  37.     Q_OBJECT
  38.  
  39. public:
  40.     KIconCanvas(QWidget *parent=0L, const char *name=0L);
  41.     ~KIconCanvas();
  42.  
  43.     /**
  44.      * Load icons into the canvas.
  45.      */
  46.     void loadFiles(const QStringList& files);
  47.  
  48.     /**
  49.      * Returns the current icon.
  50.      */
  51.     QString getCurrent() const;
  52.  
  53. public slots:
  54.     void stopLoading();
  55.  
  56. signals:
  57.     /**
  58.      * Emitted when the current icon has changed.
  59.      */
  60.     void nameChanged(QString);
  61.     /* KDE 4: Make it const QString & */
  62.  
  63.     void startLoading(int);
  64.     void progress(int);
  65.     void finished();
  66.  
  67. private slots:
  68.     void slotLoadFiles();
  69.     void slotCurrentChanged(QIconViewItem *item);
  70.  
  71. private:
  72.     QStringList mFiles;
  73.     QTimer *mpTimer;
  74.     KIconLoader *mpLoader; // unused
  75.  
  76. protected:
  77.     virtual void virtual_hook( int id, void* data );
  78.  
  79. private:
  80.     class KIconCanvasPrivate;
  81.     KIconCanvasPrivate *d;
  82. };
  83.  
  84.  
  85. /**
  86.  * Dialog for interactive selection of icons. Use the function
  87.  * getIcon() let the user select an icon.
  88.  *
  89.  * @short An icon selection dialog.
  90.  */
  91. class KIO_EXPORT KIconDialog: public KDialogBase
  92. {
  93.     Q_OBJECT
  94.  
  95. public:
  96.     /**
  97.      * Constructs an icon selection dialog using the global iconloader.
  98.      */
  99.     KIconDialog(QWidget *parent=0L, const char *name=0L);
  100.     /**
  101.      * Constructs an icon selection dialog using a specific iconloader.
  102.      */
  103.     KIconDialog(KIconLoader *loader, QWidget *parent=0,
  104.         const char *name=0);
  105.     /**
  106.      * Destructs the dialog.
  107.      */
  108.     ~KIconDialog();
  109.  
  110.     /**
  111.      * Sets a strict icon size policy for allowed icons. When true,
  112.      * only icons of the specified group's size in getIcon() are shown.
  113.      * When false, icons not available at the desired group's size will
  114.      * also be selectable.
  115.      */
  116.     void setStrictIconSize(bool b);
  117.     /**
  118.      * Returns true if a strict icon size policy is set.
  119.      */
  120.     bool strictIconSize() const;
  121.     /**
  122.      * sets a custom icon directory
  123.      * @since 3.1
  124.      */
  125.     void setCustomLocation( const QString& location );
  126.  
  127.     /**
  128.      * Sets the size of the icons to be shown / selected.
  129.      * @see KIcon::StdSizes
  130.      * @see iconSize
  131.      */
  132.     void setIconSize(int size);
  133.  
  134.     /**
  135.      * Returns the iconsize set via setIconSize() or 0, if the default
  136.      * iconsize will be used.
  137.      */
  138.     int iconSize() const;
  139.  
  140. #ifndef KDE_NO_COMPAT
  141.     /**
  142.      * @deprecated in KDE 3.0, use the static method getIcon instead.
  143.      */
  144.     QString selectIcon(KIcon::Group group=KIcon::Desktop, KIcon::Context
  145.         context=KIcon::Application, bool user=false);
  146. #endif
  147.  
  148.     /**
  149.      * Allows you to set the same parameters as in the class method
  150.      * getIcon().
  151.      */
  152.     void setup( KIcon::Group group,
  153.                 KIcon::Context context = KIcon::Application,
  154.                 bool strictIconSize = false, int iconSize = 0,
  155.                 bool user = false );
  156.  
  157.     /**
  158.      * Allows you to set the same parameters as in the class method
  159.      * getIcon(), as well as two additional parameters to lock
  160.      * the choice between system and user dirs and to lock the custom user
  161.      * dir itself.
  162.      *
  163.      * @since 3.3
  164.      */
  165.  
  166.     void setup( KIcon::Group group, KIcon::Context context,
  167.                 bool strictIconSize, int iconSize, bool user, bool lockUser,
  168.                 bool lockCustomDir );
  169.  
  170.     /**
  171.      * exec()utes this modal dialog and returns the name of the selected icon,
  172.      * or QString::null if the dialog was aborted.
  173.      * @returns the name of the icon, suitable for loading with KIconLoader.
  174.      * @see getIcon
  175.      */
  176.     QString openDialog();
  177.  
  178.     /**
  179.      * show()es this dialog and emits a newIcon(const QString&) signal when
  180.      * successful. QString::null will be emitted if the dialog was aborted.
  181.      */
  182.     void showDialog();
  183.  
  184.     /**
  185.      * Pops up the dialog an lets the user select an icon.
  186.      *
  187.      * @param group The icon group this icon is intended for. Providing the
  188.      * group shows the icons in the dialog with the same appearance as when
  189.      * used outside the dialog.
  190.      * @param context The initial icon context. Initially, the icons having
  191.      * this context are shown in the dialog. The user can change this.
  192.      * @param strictIconSize When true, only icons of the specified group's size
  193.      * are shown, otherwise icon not available in the desired group's size
  194.      * will also be selectable.
  195.      * @param iconSize the size of the icons -- the default of the icongroup
  196.      *        if set to 0
  197.      * @param user Begin with the "user icons" instead of "system icons".
  198.      * @param parent The parent widget of the dialog.
  199.      * @param caption The caption to use for the dialog.
  200.      * @return The name of the icon, suitable for loading with KIconLoader.
  201.      * @version New in 3.0
  202.      */
  203.     static QString getIcon(KIcon::Group group=KIcon::Desktop,
  204.                            KIcon::Context context=KIcon::Application,
  205.                            bool strictIconSize=false, int iconSize = 0,
  206.                            bool user=false, QWidget *parent=0,
  207.                            const QString &caption=QString::null);
  208.  
  209. signals:
  210.     void newIconName(const QString&);
  211.  
  212. protected slots:
  213.     void slotOk();
  214.  
  215. private slots:
  216.     void slotButtonClicked(int);
  217.     void slotContext(int);
  218.     void slotStartLoading(int);
  219.     void slotProgress(int);
  220.     void slotFinished();
  221.     void slotAcceptIcons();
  222. private:
  223.     void init();
  224.     void showIcons();
  225.     void setContext( KIcon::Context context );
  226.  
  227.     int mGroupOrSize;
  228.     KIcon::Context mContext;
  229.     int mType;
  230.  
  231.     QStringList mFileList;
  232.     QComboBox *mpCombo;
  233.     QPushButton *mpBrowseBut;
  234.     QRadioButton *mpRb1, *mpRb2;
  235.     KProgress *mpProgress;
  236.     KIconLoader *mpLoader;
  237.     KIconCanvas *mpCanvas;
  238.     int mNumContext;
  239.     KIcon::Context mContextMap[ 12 ]; // must match KIcon::Context size, code has assert
  240.  
  241. protected:
  242.     virtual void virtual_hook( int id, void* data );
  243. private:
  244.     class KIconDialogPrivate;
  245.     KIconDialogPrivate *d;
  246. };
  247.  
  248.  
  249. /**
  250.  * A pushbutton for choosing an icon. Pressing on the button will open a
  251.  * KIconDialog for the user to select an icon. The current icon will be
  252.  * displayed on the button.
  253.  *
  254.  * @see KIconDialog
  255.  * @short A push button that allows selection of an icon.
  256.  */
  257. class KIO_EXPORT KIconButton: public QPushButton
  258. {
  259.     Q_OBJECT
  260.     Q_PROPERTY( QString icon READ icon WRITE setIcon RESET resetIcon )
  261.     Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize)
  262.     Q_PROPERTY( bool strictIconSize READ strictIconSize WRITE setStrictIconSize )
  263.  
  264. public:
  265.     /**
  266.      * Constructs a KIconButton using the global iconloader.
  267.      */
  268.     KIconButton(QWidget *parent=0L, const char *name=0L);
  269.  
  270.     /**
  271.      * Constructs a KIconButton using a specific KIconLoader.
  272.      */
  273.     KIconButton(KIconLoader *loader, QWidget *parent, const char *name=0L);
  274.     /**
  275.      * Destructs the button.
  276.      */
  277.     ~KIconButton();
  278.  
  279.     /**
  280.      * Sets a strict icon size policy for allowed icons. When true,
  281.      * only icons of the specified group's size in setIconType are allowed,
  282.      * and only icons of that size will be shown in the icon dialog.
  283.      */
  284.     void setStrictIconSize(bool b);
  285.     /**
  286.      * Returns true if a strict icon size policy is set.
  287.      */
  288.     bool strictIconSize() const;
  289.  
  290.     /**
  291.      * Sets the icon group and context. Use KIcon::NoGroup if you want to
  292.      * allow icons for any group in the given context.
  293.      */
  294.     void setIconType(KIcon::Group group, KIcon::Context context, bool user=false);
  295.  
  296.     /**
  297.      * Sets the button's initial icon.
  298.      */
  299.     void setIcon(const QString& icon);
  300.  
  301.     /**
  302.      * Resets the icon (reverts to an empty button).
  303.      */
  304.     void resetIcon();
  305.  
  306.     /**
  307.      * Returns the name of the selected icon.
  308.      */
  309.     QString icon() const { return mIcon; }
  310.  
  311.     /**
  312.      * Sets the size of the icon to be shown / selected.
  313.      * @see KIcon::StdSizes
  314.      * @see iconSize
  315.      */
  316.     void setIconSize( int size );
  317.  
  318.     /**
  319.      * Returns the iconsize set via setIconSize() or 0, if the default
  320.      * iconsize will be used.
  321.      */
  322.     int iconSize() const;
  323.  
  324. signals:
  325.     /**
  326.      * Emitted when the icon has changed.
  327.      */
  328.     void iconChanged(QString icon);
  329.     /* KDE 4: Make it const QString & */
  330.  
  331. private slots:
  332.     void slotChangeIcon();
  333.     void newIconName(const QString& name);
  334.  
  335. private:
  336.     void init( KIconLoader *loader );
  337.  
  338.     bool mbUser;
  339.     KIcon::Group mGroup;
  340.     KIcon::Context mContext;
  341.  
  342.     QString mIcon;
  343.     KIconDialog *mpDialog;
  344.     KIconLoader *mpLoader;
  345.     class KIconButtonPrivate;
  346.     KIconButtonPrivate *d;
  347. };
  348.  
  349.  
  350. #endif // __KIconDialog_h__
  351.